package cn.accp.mvc.entity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@SuppressWarnings("unchecked")
@Repository("page")
public class Page extends SqlSessionDaoSupport{
	@Autowired
	@Override
	public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
		// TODO Auto-generated method stub
		super.setSqlSessionFactory(sqlSessionFactory);
	}
	private int pageSize = 0;
	private int currPageNo = 1;
	private int totalPageCount = 1;
	private int recordCount = 0;
	
	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getCurrPageNo() {
		return currPageNo;
	}

	public void setCurrPageNo(int currPageNo) {
		this.currPageNo = currPageNo;
	}

	public int getTotalPageCount() {
		return totalPageCount;
	}

	public void setTotalPageCount(int totalPageCount) {
		this.totalPageCount = totalPageCount;
	}

	public int getRecordCount() {
		return recordCount;
	}

	public void setRecordCount(int recordCount) {
		this.recordCount = recordCount;
	}

	public int getStartRow(){
		return (currPageNo - 1) * pageSize;
	}
	
	public List<allEntity> findHouseByPage(int pageNo,int pageSize){
		List<allEntity> housesList = new ArrayList<allEntity>();
		HashMap paraMap = new HashMap();
		Page page = new Page();
		page.setCurrPageNo(pageNo);
		page.setPageSize(pageSize);
		paraMap.put("startRow", page.getStartRow());
		paraMap.put("endRow", pageSize);
		housesList = getSqlSession().selectList("findAllEntityByPage", paraMap);
		return housesList;
	}
}
